<?php
define("DSN", "mysql:host=localhost;dbname=Lab20");
define("DB_USER", "root");
define("DB_PWD",  "123456");

$type = $_REQUEST['type'];
try{
	$pdo = new PDO(DSN, DB_USER, DB_PWD);
	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$pdo->exec("set names utf8");
}
catch (Exception $e){
	echo $e->getMessage();
}

try{
	$stmt = $pdo->prepare("SELECT * FROM `news` WHERE `type`=:type");
	$stmt->bindParam(":type", $type);
	$stmt->execute();
	$news = $stmt->fetchAll(PDO::FETCH_ASSOC);
	echo "<ul>\n";
	foreach($news as $new) {
		echo <<<STR
		<li><a href="viewNews.php?id={$new['id']}">{$new['title']}</a></li>\n
STR;
	}
	echo "</ul>";
}
catch(PDOException $e){
	echo $e->getMessage();
}